/**
 *  @author Cornelius Huang
 *  skill module service
 */
app.factory('getSkillService', ['$http', '$q', function($http, $q) {
	var baseUrl = '/DRMS/api';
	return {
		getSkills: function() {
			var promise = $q(function(resolve, reject) {
				$http({
					url: baseUrl + '/DrmsCategory/fianAllCategories',
					method: 'POST'
				}).then(function(response) {
					resolve(response.data);
				}, function() {
					reject('getSkillService - getSkills reject');
				});
			});
			return promise;
		},
		getSkillInfo: function(username) {
			var promise = $q(function(resolve, reject) {
				$http({
					url: baseUrl + '/skillmatrix/getSkillMatrix?username=' + username,
					method: 'GET'
				}).then(function(response) {
					resolve(response.data);
				}, function() {
					reject('getSkillService - getSkillInfo reject');
				})
			});
			return promise;
		},
		updateSkills: function(skills) {
			var promise = $q(function(resolve, reject) {
				$http({
					url: baseUrl + '/skillmatrix/updateOrAdd',
					method: 'POST',
					data: skills
				}).then(function(response) {
					resolve(response.data);
				}, function() {
					reject('getSkillService - updateSkills reject');
				})
			});
			return promise;
		},
		getLevel: function() {
			var promise = $q(function(resolve, reject) {
				$http({
					url: '/DRMS/data/level.json',
					method: 'GET'
				}).then(function(response) {
					resolve(response.data);
				}, function() {
					reject('getSkillService - getLevel reject');
				})
			});
			return promise;
		}
		
	}
}])